<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>PDF Upload</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            margin: 20px;
        }
        .container {
            width: 50%;
            margin: 0 auto;
            padding: 20px;
            border: 1px solid #ccc;
            border-radius: 5px;
            background-color: #f9f9f9;
        }
        .form-group {
            margin-bottom: 10px;
        }
        .form-group label {
            font-weight: bold;
            display: block;
            margin-bottom: 5px;
        }
        .form-group input[type="file"] {
            display: block;
            width: 100%;
            padding: 8px;
            font-size: 16px;
            border: 1px solid #ccc;
            border-radius: 4px;
        }
        .form-group button {
            background-color: #4CAF50;
            color: white;
            padding: 10px 20px;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            font-size: 16px;
        }
        .form-group button:hover {
            background-color: #45a049;
        }
    </style>
</head>
<body>
<div class="container">
    <h2>Upload PDF File</h2>
    <form id="uploadForm" enctype="multipart/form-data">
        <div class="form-group">
            <label for="pdfFile">Choose PDF file:</label>
            <input type="file" id="pdfFile" name="file" accept=".pdf" required>
        </div>
        <div class="form-group">
            <button type="submit">Upload</button>
        </div>
    </form>
    <div id="message"></div>
</div>

<script>
    const form = document.getElementById('uploadForm');
    const messageDiv = document.getElementById('message');

    form.addEventListener('submit', async function(event) {
        event.preventDefault();

        const formData = new FormData();
        formData.append('file', document.getElementById('pdfFile').files[0]);

        try {
            const response = await fetch('/api/v1/pdf/upload', {
                method: 'POST',
                body: formData
            });

            if (!response.ok) {
                throw new Error(`HTTP error! Status: ${response.status}`);
            }

            messageDiv.textContent = 'File uploaded successfully!';
            messageDiv.style.color = 'green';
            form.reset(); // Reset the form after successful upload
        } catch (error) {
            console.error('Error:', error);
            messageDiv.textContent = 'Error uploading file. Please try again.';
            messageDiv.style.color = 'red';
        }
    });
</script>

</body>
</html>
